/*
  Warnings:

  - Added the required column `groupId` to the `Student` table without a default value. This is not possible if the table is not empty.
  - Added the required column `otdelenieId` to the `Group` table without a default value. This is not possible if the table is not empty.

*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Student" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "userId" INTEGER,
    "familiya" TEXT NOT NULL,
    "imya" TEXT NOT NULL,
    "otchestvo" TEXT NOT NULL,
    "birthday" DATETIME NOT NULL,
    "groupId" INTEGER NOT NULL,
    CONSTRAINT "Student_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
    CONSTRAINT "Student_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Student" ("birthday", "familiya", "id", "imya", "otchestvo", "userId") SELECT "birthday", "familiya", "id", "imya", "otchestvo", "userId" FROM "Student";
DROP TABLE "Student";
ALTER TABLE "new_Student" RENAME TO "Student";
CREATE UNIQUE INDEX "Student_userId_key" ON "Student"("userId");
CREATE TABLE "new_Group" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "curatorId" INTEGER NOT NULL,
    "year" INTEGER NOT NULL,
    "title" TEXT NOT NULL,
    "otdelenieId" INTEGER NOT NULL,
    CONSTRAINT "Group_curatorId_fkey" FOREIGN KEY ("curatorId") REFERENCES "Prepodavatel" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "Group_otdelenieId_fkey" FOREIGN KEY ("otdelenieId") REFERENCES "Otdelenie" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Group" ("curatorId", "id", "title", "year") SELECT "curatorId", "id", "title", "year" FROM "Group";
DROP TABLE "Group";
ALTER TABLE "new_Group" RENAME TO "Group";
CREATE UNIQUE INDEX "Group_curatorId_key" ON "Group"("curatorId");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
